import globals.DrawPadSize;

import java.awt.Toolkit;

import javax.swing.JComponent;
import javax.swing.JOptionPane;


public class ImageOperation extends JComponent {
	
	private String response1, response2;
	private int width, height;
	private int xSize, ySize;

	//Constructor
	ImageOperation(){
		
		//temporary solution used to allow working with large images without scroll pane
		//this solution however makes impossible work with images close or greater than 
		//computer's resolution
		//tested only on Windows
		//TODO: if scroll pane is implemented, change values of max sizes 
		Toolkit tk = Toolkit.getDefaultToolkit();  
		xSize = ((int) tk.getScreenSize().getWidth());  
		ySize = ((int) tk.getScreenSize().getHeight()); 
	}
	
	public void setSize(){
		 response1 = (String) JOptionPane.showInputDialog(null, "1 : " + (xSize - 80) , "New width", JOptionPane.QUESTION_MESSAGE, null, null, DrawPadSize.getWidth());
		 if(response1 != null){
			 try {
				 width = Integer.parseInt(response1);
			 }
			 catch(Exception e)
			 {
				 JOptionPane.showMessageDialog(null, "Data you entered is not a number. Width value will remain unchanged", "Invalid data", JOptionPane.ERROR_MESSAGE);
				 width = DrawPadSize.getWidth();
			 }
			 if(width < 1 || width> (xSize - 80)){
				 JOptionPane.showMessageDialog(null, "Data you entered is out of range", "Unable to set width", JOptionPane.ERROR_MESSAGE);
			 }
			 else{
				 response2 = (String) JOptionPane.showInputDialog(null, "1 : " + (ySize - 90), "New width", JOptionPane.QUESTION_MESSAGE, null, null, DrawPadSize.getHeight());
				 if(response2 != null){
					 try {
						 height = Integer.parseInt(response2);
					 }
					 catch(Exception e)
					 {
						 JOptionPane.showMessageDialog(null, "Data you entered is not a number. Height value will remain unchanged", "Invalid data", JOptionPane.ERROR_MESSAGE);
						 height = DrawPadSize.getHeight();
					 }
					 if(height < 1 || height > (ySize - 90)){
						 JOptionPane.showMessageDialog(null, "Data you entered is out of range", "Unable to set height", JOptionPane.ERROR_MESSAGE);
					 }
					 else {
						 DrawPadSize.setWidth(width);
						 DrawPadSize.setHeight(height);
						 System.out.println(DrawPadSize.getWidth());
					     System.out.println(DrawPadSize.getHeight());
					 }
				 }
			 }
		 }
	}
}
